from pms.common.views import PostFormula
from project.models import ProjectCodeRepository
from project.utils.repository import repository_view
from project.utils.permission import assert_project_permissions


class API(PostFormula):

    def handle(self, req):
        repo_id = req['id']
        repo = ProjectCodeRepository.objects.get(id=repo_id)
        assert_project_permissions(repo.pid_id, self.user.id, [2])
        view = repository_view(repo)
        repo.delete()
        return self.success_respond(view)
